package client;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import server.BkCAccITF;
import server.BkStfITF;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import client.Configuration;

public class BkStaffWorkGUI extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	
	Configuration config=new Configuration();
	String rmiAddress=config.getRmiAddress();
	BkCAccITF CAitf;
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BkStaffWorkGUI frame = new BkStaffWorkGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public BkStaffWorkGUI() {
		setTitle("\u804C\u5DE5\u64CD\u4F5C");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton button = new JButton("查看账户密码");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					CAitf = (BkCAccITF) Naming.lookup(rmiAddress+"BankCurrentAccount");
					String sID = JOptionPane.showInputDialog("请输入要查看的账户身份证号：");   
					int pID = Integer.parseInt(sID);
					JOptionPane.showMessageDialog(null, "该账户的密码为："+CAitf.getKey(pID));
				} catch (MalformedURLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (NotBoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			
			}
		});
		button.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		button.setBounds(145, 60, 135, 48);
		contentPane.add(button);
		
		JButton button_5 = new JButton("\u8FD4\u56DE");
		button_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BkStaffLoginGUI frame = new BkStaffLoginGUI();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
				dispose();
			}
		});
		button_5.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		button_5.setBounds(341, 10, 83, 22);
		contentPane.add(button_5);
		
		JButton button_1 = new JButton("修改账户密码");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					CAitf = (BkCAccITF) Naming.lookup(rmiAddress+"BankCurrentAccount");
					String sID = JOptionPane.showInputDialog("请输入将修改的账户身份证号：");
				    int pID = Integer.parseInt(sID);
			  	    String skey = JOptionPane.showInputDialog("请输入新密码：");
				    int pkey = Integer.parseInt(skey);
				    if(CAitf.changeKey(pID, pkey))
				    	JOptionPane.showMessageDialog(null, "修改成功！");
				    else
				    	JOptionPane.showMessageDialog(null, "用户ID不存在或操作失败！");
				} catch (MalformedURLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (NotBoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		button_1.setBounds(145, 118, 133, 48);
		contentPane.add(button_1);
	}
}
